//
//  WKAddressAddVM.m
//  LLWallet
//
//  Created by wangfei on 2025/9/15.
//

#import "WKAddressAddVM.h"

#import "FFBankcardAddInputCell.h"
#import "FFBankcardAddNextVC.h"
#import "WKCoinVC.h"


@interface WKAddressAddVM ()

@property(nonatomic,strong,nullable) NSString *address;

@property(nonatomic,strong,nullable) NSMutableArray *biArr;
@end

@implementation WKAddressAddVM


static WKAddressAddVM *_instance = nil;

+(instancetype)allocWithZone:(struct _NSZone *)zone{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone ];
    });
    return _instance;
}

+(instancetype) shared{
    if (_instance == nil) {
        _instance = [[super alloc]init];
    }
    return _instance;
}

- (NSArray<NSDictionary *> *)tableSectionMaps {
    
    __weak typeof(self) weakSelf = self;
    NSMutableArray *items = [NSMutableArray array];
    
    return @[
        @{
            @"height":@(10.0f),
            @"items":@[@{
                @"class":WKLabelItemModel.class,
                @"label":LLang(@"提币类型"),
                @"value":self.selectBi.name?self.selectBi.name:@"",
                @"onClick":^{
                    if(weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(ff_coinSelect:)]) {
                        [weakSelf.delegate ff_coinSelect:self.selectBi];
                    }
                }
            }]
                        
        },
        @{
            @"height":@(10.0f),
            @"items":@[@{
                @"class": WKAddressAddInputModel.class,
                @"label": LLang(@"提币地址"),
                @"placeholder":LLang(@"输入或粘贴地址"),
                @"onChange":^(NSString *value){
                    self.address = value;
                }
            }]
        },
        @{
            @"height": @(40.0f),
            @"items": @[
                    @{
                        @"class": WKButtonItemModel2.class,
                        @"title": LLang(@"添加"),
                        @"onPressed":^{
                            if (!self.selectBi){
                                [[WKNavigationManager shared].topViewController.view showMsg:@"请选择币种"];
                                return;
                            }
                            if (!self.address){
                                [[WKNavigationManager shared].topViewController.view showMsg:@"请输入地址"];
                                return;
                            }
                            [weakSelf addAddress];
                        },
                    }
            
            ],
        }
    ];
}

-(AnyPromise*) addAddress {
    
    return  [[WKAPIClient sharedClient] POST:@"udun/user/address" parameters:@{@"address":self.address,@"id":self.selectBi._id}].then(^(NSDictionary *resultDict){
        [[WKNavigationManager shared] popViewControllerAnimated:YES];
    });
}

@end
